/*package ru.st.selenium;

import org.testng.annotations.Test;
import org.testng.AssertJUnit;

import java.io.File;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;

import org.testng.*;
import org.testng.annotations.*;

import static org.hamcrest.CoreMatchers.*;

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.internal.seleniumemulation.IsTextPresent;
import org.openqa.selenium.support.ui.Select;

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;


public class AddFilm extends ru.st.selenium.pages.TestBase {
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();
  
  @Test(priority=1)
  public void testLogin() throws Exception {    
  driver.get(baseUrl + "/php4dvd/");
  WebElement usename = driver.findElement(By.id("username"));
  usename.clear();
  usename.sendKeys("admin");
  WebElement passwordField = driver.findElement(By.name("password"));
  passwordField.clear();
  passwordField.sendKeys("admin");
  driver.findElement(By.name("submit")).click();
   }


  @Test(priority=2)
  public void testAdd() throws Exception {    
	driver.get(baseUrl + "/php4dvd/#!/sort/name%20asc/");
    driver.findElement(By.cssSelector("img[alt=\"Add movie\"]")).click();
    driver.findElement(By.id("imdbsearch")).clear();
    driver.findElement(By.id("imdbsearch")).sendKeys("Gravity");
    driver.findElement(By.name("imdbid")).clear();
    driver.findElement(By.name("imdbid")).sendKeys("1");
    driver.findElement(By.name("name")).sendKeys(Keys.CONTROL + "a");
    Thread.sleep(200);
    driver.findElement(By.name("name")).sendKeys(Keys.DELETE);
    driver.findElement(By.name("name")).sendKeys("Gravity");
    driver.findElement(By.name("aka")).clear();
    driver.findElement(By.name("aka")).sendKeys("Gravity");
    driver.findElement(By.name("year")).clear();
    driver.findElement(By.name("year")).sendKeys("2013");
    driver.findElement(By.name("duration")).clear();
    driver.findElement(By.name("duration")).sendKeys("90");
    driver.findElement(By.name("rating")).clear();
    driver.findElement(By.name("rating")).sendKeys("8.3");
    File file = new File ("C:/Git/se-java-shykhovtsova/src/test/resources/468466.jpg");
    driver.findElement(By.id("cover")).sendKeys(file.getAbsolutePath());
    driver.findElement(By.name("trailer")).clear();
    driver.findElement(By.name("trailer")).sendKeys("http://www.kinopoisk.ru/film/468466/");
    driver.findElement(By.name("taglines")).clear();
    driver.findElement(By.name("taglines")).sendKeys("Do not let go");
    driver.findElement(By.name("plots")).clear();
    putToClipboard("Dr. Ryan Stone, a brilliant expert in the field of medical engineering , goes on his first space mission , commanded by veteran Astronautics Matt Kowalski, for which the flight - the last before retirement . But while seemingly routine work behind a disaster happens .\n\nThe shuttle is destroyed, and Stone and Kowalsky completely alone remain , and they are in conjunction with each other, and all they can - is moving in an orbit in a completely black space with no connection to the Earth and any hope of rescue.");
    driver.findElement(By.name("plots")).sendKeys(Keys.CONTROL + "v");
    // driver.findElement(By.name("plots")).sendKeys("Dr. Ryan Stone, a brilliant expert in the field of medical engineering , goes on his first space mission , commanded by veteran Astronautics Matt Kowalski, for which the flight - the last before retirement . But while seemingly routine work behind a disaster happens .\n\nThe shuttle is destroyed, and Stone and Kowalsky completely alone remain , and they are in conjunction with each other, and all they can - is moving in an orbit in a completely black space with no connection to the Earth and any hope of rescue.");
    driver.findElement(By.id("text_languages_0")).clear();
    driver.findElement(By.id("text_languages_0")).sendKeys("English");
    driver.findElement(By.name("country")).clear();
    driver.findElement(By.name("country")).sendKeys("USA");
    driver.findElement(By.name("genres")).clear();
    driver.findElement(By.name("genres")).sendKeys("Fantasy\nThriller\nDrama");
    driver.findElement(By.name("director")).clear();
    driver.findElement(By.name("director")).sendKeys("Alfonso Cuaron");
    driver.findElement(By.name("writer")).clear();
    driver.findElement(By.name("writer")).sendKeys("Alfonso Cuaron");
    driver.findElement(By.name("producer")).clear();
    driver.findElement(By.name("producer")).sendKeys("Alfonso Cuaron");
    driver.findElement(By.name("music")).clear();
    driver.findElement(By.name("music")).sendKeys("Steven Price");
    driver.findElement(By.id("submit")).click();
   }
  
  @Test(priority=3)
  public void testError() throws Exception {   
	  driver.findElement(By.linkText("Home")).click();
	  driver.findElement(By.xpath("//img[@title='Add movie']")).click();
	  driver.findElement(By.name("name")).clear();
	  driver.findElement(By.name("name")).sendKeys("Gravity");
	  driver.findElement(By.id("submit")).click();
	  AssertJUnit.assertTrue(isTextPresent("This field is required"));
  }
 
  
  @Test(priority=4)
  public void testLogout() throws Exception {    
	driver.get(baseUrl + "/php4dvd/#!/sort/name%20asc/");
    driver.findElement(By.linkText("Log out")).click();
    AssertJUnit.assertTrue(closeAlertAndGetItsText().matches("^Are you sure you want to log out[\\s\\S]$"));
   }

  
  private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }

  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      String alertText = alert.getText();
      if (acceptNextAlert) {
        alert.accept();
      } else {
        alert.dismiss();
      }
      return alertText;
    } finally {
      acceptNextAlert = true;
    }
  }
  protected boolean isTextPresent(String text){
	    try{
	        boolean b = driver.getPageSource().contains(text);
	        return b;
	    }
	    catch(Exception e){
	        return false;
	    }
	  }
  private void putToClipboard(String str) {
      Clipboard clbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
      StringSelection strsel = new StringSelection(str);                  
      clbrd.setContents(strsel, null);
  }
}*/